﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Deflection
{
    public class MenuItem
    {
        public Vector2 Position { get; set; }
        public string Text { get; set; }
        public bool Active { get; set; }



        public delegate void OnSelectEventHandler(int index);
        public event OnSelectEventHandler Selected;

        public int Index { get; set; } // The index of the menu item


        protected void OnSelection(int index)
        {
            // Check if there are any Subscribers
            if (Selected != null)
            {
                // Call the Event
                Selected(index);
            }
        }

        public MenuItem(string text, Vector2 position, int index)
        {
            Text = text;
            Position = position;
            Index = index;
        }

        public virtual void Update(GameTime gameTime)
        {

        }

        public virtual void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {

            Vector2 textSize = GameParameters.GAME_FONT.MeasureString(Text);
            if (Active)
            {
                spriteBatch.DrawString(GameParameters.GAME_FONT, Text, Position, Color.Red, 0f, (textSize / 2), 1f, SpriteEffects.None, 0f);      
            }
            else
            {
                spriteBatch.DrawString(GameParameters.GAME_FONT, Text, Position, Color.Black, 0f, (textSize / 2), 1f, SpriteEffects.None, 0f);
            }
        }

        /// <summary>
        /// Called when a menu items is chosen (presse enter)
        /// </summary>
        public virtual void Select()
        {
            // Fire the event
            OnSelection(Index);
        }

    }
}
